package com.project.service.ipml;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.project.bean.EmployeeBean;
import com.project.mapper.IEmployeeMapper;
import com.project.service.IEmployeeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalDate;
import java.util.List;

@Service
@Transactional
public class EmployeeServiceImpl implements IEmployeeService {
    @Autowired
    private IEmployeeMapper mapper;

    @Override
    public void add(EmployeeBean employeeBean) {
        mapper.add(employeeBean);
    }

    @Override
    public void updateStatus(Integer id) {
        mapper.updateStatus(id);
        mapper.updateFinnishDate(id, String.valueOf(LocalDate.now()));
    }

    @Override
    public void updateSalaryPhone(Integer id, int newWages, String newPhone) {
        mapper.updateSalaryPhone(id, newWages, newPhone);
    }

    @Override
    public EmployeeBean findById(Integer id) {
        return mapper.findById(id);
    }

    @Override
    public PageInfo<EmployeeBean> cutPageFindByItem(int pageNO, String name, String specialty, String status, String order) {
        PageHelper.startPage(pageNO, 3);
        PageInfo<EmployeeBean> pageInfo = PageInfo.of(mapper.cutPageFindByItem(name, specialty, status, order));
        return pageInfo;
    }

    @Override
    public List<EmployeeBean> findByItem(Integer id, String specialty, String name) {
        return mapper.findByItem(id, specialty, name);
    }

    @Override
    public EmployeeBean findByStaffId(Integer id) {
        return mapper.findByStaffId(id);
    }
}
